# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

require 'Vu/all'

module Vu
	class Button
		def render_glossline (cr, x, y, width, height, top)
			sz = 20 # width of curve
			if top
				cr.move_to(x,y)
			else
				cr.move_to(x+width,y+height)
			end
			cr.line_to(x+width,y)
			cr.curve_to(x+width,y+height/2, x+width,y+height/2, x+width-sz, y+height/2)
			cr.line_to(x+sz,y+height/2)
			cr.curve_to(x,y+height/2, x,y+height/2, x,y+height)
			cr.close_path
		end
	
		def hilight_colour
			if @uberfocus
				Vu::RGB.new(0.9,0.95,1)
			elsif @focus
				Vu::RGB.new(1,1,1)
			else
				Vu::RGB.new(0.85,0.86,0.87,0.9)
			end
		end
	
		def render (cr)
			
			# The fill
			fill = Cairo::LinearPattern.new(0,0,0,height)
			fill.add_stop(0.0, hilight_colour)
			fill.add_stop(0.5, Vu::RGB.new(0.5,0.5,0.5,0.98))
			fill.add_stop(1.0, hilight_colour.darker(0.2))
			
			# Fill the inner
			cr.save
			cr.set_source(fill)
			cr.rounded_rectangle(1.5,1.5,width-3,height-3, 6)
			cr.paint
			cr.restore
			
			cr.rounded_rectangle(1.5,1.5,width-3,height-3, 6)				
			if @uberfocus
				cr.set_source_rgb(0,0,0)
			elsif @focus
				cr.set_source_rgb(0.25,0.25,0.25)
			else
				cr.set_source_rgba(0.5,0.5,0.5)
			end
			
			cr.line_width = 1
			cr.stroke
			
			render_children(cr)
		end
	end
end

